from redis import StrictRedis
import logging


class Config(object):
    """项目配置信息"""
    DEBUG = True

    # mysql数据库配置信息
    # 数据库链接配置
    SQLALCHEMY_DATABASE_URI = 'mysql://root:mysql@127.0.0.1:3306/information19'
    # 关闭数据库修改跟踪
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis数据库配置信息
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_NUM = 9

    # 加密字符串
    SECRET_KEY = 'DKAJDHAKJDHWQNDMQNDMZKCJKJDHAJKDHWIOQDJKZNCXM'
    # 通过flask-session拓展，将flask中的session从内存调整到redis里的配置信息
    # 存储数据库的类型为redis
    SESSION_TYPE = "redis"
    # 将redis实例对象进行传入
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_NUM)
    # 对session数据进行加密处理
    SESSION_USE_SIGNER = True
    # 关闭永久存储
    SESSION_PERMANENT = False
    # 过期时长
    PERMANENT_SESSION_LIFETIME = 86400


class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True
    LOG_LEVEL = logging.DEBUG


class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False

    LOG_LEVEL = logging.WARNING


# 给外界暴露一个接口来使用这些配置类
config_dict = {
    "development": DevelopmentConfig,
    "production": ProductionConfig
}

